import React, { useState, useCallback, useRef } from 'react'

export default function App() {
  // useState 记忆函数，记住变量的状态
  const [count, setCount] = useState(0)

  // 记忆函数
  const handlePlus = useCallback(() => {
    setCount(count - 1)
  }, [count])

  // 也可以保存 状态
  let myCount = useRef(1)
  return (
    <div>
      <h1>App</h1>
      <button
        onClick={() => {
          setCount(count + 1)
          myCount.current++
        }}
      >
        +
      </button>
      <span>{count}</span>
      <button onClick={handlePlus}>-</button>
      <div>{myCount.current}</div>
    </div>
  )
}
